home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap17 / FontClip / FontClip.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  1.8 KB  |  65 lines

  1. /*-----------------------------------------------
  2.    FONTCLIP.C -- Using Path for Clipping on Font
  3.                  (c) Charles Petzold, 1998
  4.   -----------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "..\\eztest\\ezfont.h"
  8.  
  9. TCHAR szAppName [] = TEXT ("FontClip") ;
  10. TCHAR szTitle [] = TEXT ("FontClip: Using Path for Clipping on Font") ;
  11.  
  12. void PaintRoutine (HWND hwnd, HDC hdc, int cxArea, int cyArea)
  13. {
  14.      static TCHAR szString [] = TEXT ("Clipping") ;
  15.      HFONT        hFont ;
  16.      int          y, iOffset ;
  17.      POINT        pt [4] ;
  18.      SIZE         size ;
  19.  
  20.      hFont = EzCreateFont (hdc, TEXT ("Times New Roman"), 1200, 0, 0, TRUE) ;
  21.  
  22.      SelectObject (hdc, hFont) ;
  23.  
  24.      GetTextExtentPoint32 (hdc, szString, lstrlen (szString), &size) ;
  25.  
  26.      BeginPath (hdc) ;
  27.      TextOut (hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2,
  28.                     szString, lstrlen (szString)) ;
  29.      EndPath (hdc) ;
  30.  
  31.                // Set clipping area
  32.  
  33.      SelectClipPath (hdc, RGN_COPY) ;
  34.  
  35.                // Draw Bezier splines
  36.  
  37.      iOffset = (cxArea + cyArea) / 4 ;
  38.  
  39.      for (y = -iOffset ; y < cyArea + iOffset ; y++)
  40.      {
  41.           pt[0].x = 0 ;
  42.           pt[0].y = y ;
  43.  
  44.           pt[1].x = cxArea / 3 ;
  45.           pt[1].y = y + iOffset ;
  46.  
  47.           pt[2].x = 2 * cxArea / 3 ;
  48.           pt[2].y = y - iOffset ;
  49.  
  50.           pt[3].x = cxArea ;
  51.           pt[3].y = y ;
  52.  
  53.           SelectObject (hdc, CreatePen (PS_SOLID, 1,
  54.                RGB (rand () % 256, rand () % 256, rand () % 256))) ;
  55.  
  56.           PolyBezier (hdc, pt, 4) ;
  57.  
  58.           DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
  59.      }
  60.  
  61.      DeleteObject (SelectObject (hdc, GetStockObject (WHITE_BRUSH))) ;
  62.      SelectObject (hdc, GetStockObject (SYSTEM_FONT)) ;
  63.      DeleteObject (hFont) ;
  64. }
  65.